package com.jianjun.ktui

import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountBox
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import cn.hutool.core.util.StrUtil
import cn.hutool.http.GlobalInterceptor
import cn.hutool.http.HttpRequest
import cn.hutool.http.HttpResponse
import org.slf4j.Logger
import org.slf4j.LoggerFactory


fun main() = application {
    val log: Logger = LoggerFactory.getLogger(this::class.java)
    GlobalInterceptor.INSTANCE.addRequestInterceptor { httpObj: HttpRequest ->
        log.info(
            StrUtil.sub(
                httpObj.toString(),
                0,
                2000
            )
        )
    }
    GlobalInterceptor.INSTANCE.addResponseInterceptor { httpObj: HttpResponse ->
        log.info(
            StrUtil.sub(
                httpObj.toString(),
                0,
                2000
            )
        )
    }
    Window(
        onCloseRequest = ::exitApplication,
        title = "jianjun-ui",
        icon = rememberVectorPainter(Icons.Filled.AccountBox)
    ) {
        App()
    }
}

@Preview
@Composable
fun AppDesktopPreview() {
    App()
}